#include <cstdarg>
#include <cstring>
#include <cstdio>
#include <cassert>
#include "render.h"

// Should be in render.cpp
namespace Globals {
LPDIRECT3DDEVICE9  g_pd3dDevice = NULL; // Our rendering device
LPD3DXFONT         g_dbg_font = NULL;
}

void initFonts( ) {
		// Create a debug font
	HRESULT hr = D3DXCreateFont( Globals::g_pd3dDevice
		          , 20
				  , 10
				  , FW_NORMAL
				  , 1
				  , FALSE
				  , DEFAULT_CHARSET
				  , OUT_DEFAULT_PRECIS
				  , DEFAULT_QUALITY
				  , DEFAULT_PITCH|FF_DONTCARE
				  , "Arial"
				  , &Globals::g_dbg_font
				  );
	assert( hr == D3D_OK );
}

void printf2D ( float x, float y, unsigned color, const char *fmt, ... ) {
	char buf[ 1024 ];
	va_list ap;
	va_start( ap, fmt );
	int n = _vsnprintf_s( buf, sizeof( buf )-1, fmt, ap );
	assert( n < sizeof( buf ) );

	RECT rect;
	rect.left = x;
	rect.right = x + 1000;
	rect.top = y;
	rect.bottom = y + 1000;
	INT nchars = Globals::g_dbg_font->DrawText( NULL
		, buf
		, -1
		, &rect
		, DT_LEFT
		, color
		);
	assert( nchars >= 0 );

}
